package com.appkubes.fintech.restful.application.mall.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.appkubes.fintech.restful.application.mall.service.MallService;
import com.appkubes.fintech.restful.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @Author: Rongjie
 * @Date: 2020/2/29
 * @Description:
 */
@Service
@Slf4j
public class MallServiceImpl implements MallService {


    @Value("${mall.data.restfulHostUrl}")
    private String hostUrl;

    private String getHierarchyParentURL = "/user/hierarchy/getParent/{userKey}";


    @Override
    public JSONObject getUserHierarchyData(String userKey) {
        String msgStr = HttpUtils.doGet(hostUrl + getHierarchyParentURL.replace("{userKey}", userKey));
        log.info("getUserHierarchyData: {}", msgStr);
        JSONObject resultJson = JSONObject.parseObject(msgStr);

        if (resultJson == null) {
            return new JSONObject();
        }

        JSONObject data = resultJson.getJSONObject("data");
        if (data == null) {
            return new JSONObject();
        }
        return data;
    }
}
